<template>
  <!-- 人员类型详情 -->
  <el-dialog v-dialogDrag :title="dialogTitle" class="dialogStyleSmall" :visible.sync="dialogVisible">
    <el-form ref="form" :model="formData" label-width="80px">
      <el-form-item label="类型名称" prop="typeName">
        <el-input v-model="formData.typeName" readonly size="medium" placeholder />
      </el-form-item>
      <el-form-item label="类型编号" prop="typeNum">
        <el-input v-model="formData.typeNum" size="medium" readonly placeholder="" />
      </el-form-item>
      <el-form-item label="类型顺序" prop="orderNum">
        <el-input-number
          v-model="formData.orderNum"
          size="medium"
          disabled
          style="width: 100%"
          controls-position="right"
          :min="1"
        />
      </el-form-item>
      <el-form-item label="拥有功能" prop="power">
        <el-checkbox-group readonly :value="formData.power">
          <el-checkbox label="describe">描述功能</el-checkbox>
          <el-checkbox label="allot">分配功能</el-checkbox>
          <el-checkbox label="patrol">巡检功能</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-col :span="24">
        <el-form-item label="">
          <label slot="label" v-html="`备&emsp;&emsp;注`" />
          <el-input v-model="formData.remark" readonly :rows="3" type="textarea" />
        </el-form-item>
      </el-col>
    </el-form>
  </el-dialog>
</template>

<script>
import { detailPersonSupperType } from '@/api/superviseBaseInfo/typeManage/personnelType'
export default {
  name: 'DetailDialog',
  data() {
    return {
      /* 新增 start */
      dialogVisible: false,
      dialogTitle: '',
      formData: {
        id: '',
        typeName: '',
        remark: '',
        typeNum: '',
        orderNum: '',
        power: []
      }
      /* 新增 end */
    }
  },
  methods: {
    /* 详情 start */
    handleAdd(title, id) {
      this.dialogVisible = true
      this.dialogTitle = title
      this.getDetailById(id)
    },
    // 获取详情
    async getDetailById(id) {
      const { data } = await detailPersonSupperType(id)
      this.formData = { ...this.formData, ...data }

      const { allot, describe, patrol } = data
      if (allot === '0') this.formData.power.push('allot')
      if (describe === '0') this.formData.power.push('describe')
      if (patrol === '0') this.formData.power.push('patrol')
    },
    // 关闭弹窗
    cancel() {
      this.resetForm('form')
      this.dialogVisible = false
      this.formData.allot = ''
      this.formData.describe = ''
      this.formData.patrol = ''
    }
    /* 详情 end */
  }
}
</script>

